#!/bin/sh

OLD_MOUNT_PATH=/media/sdcard

# 1) Test if symlink already exist
# 2) Cleanup old empty mount points
# 3) Create symlink

if [ -L $OLD_MOUNT_PATH ]; then
  exit 0
fi

DEVICEUSER=$(loginctl list-sessions | grep seat0 | tr -s " " | cut -d " " -f 4)
for path in ${OLD_MOUNT_PATH}/*
do
  rmdir ${path}
done

rmdir ${OLD_MOUNT_PATH}
ln -s /run/media/${DEVICEUSER} ${OLD_MOUNT_PATH}
exit $?
